package com.tgy.树.二叉树;

/***
 * @ClassName: BinaryTreeDemo
 * @Description: 学习二叉树的遍历
 * @Auther: tanggy3
 * @Date: 17:06 2022/12/21
 * @version : V1.0
 */
public class BinaryTreeFind {
    public static void main(String[] args) {
        //先需要创建一颗二叉树
        BinaryTree binaryTree = new BinaryTree();
        //创建需要的结点
        Node node2 = new Node(1, "宋江");
        Node root = new Node(2, "吴用");
        Node node3 = new Node(3, "卢俊义");
        Node node4 = new Node(4, "林冲");
        Node node5 = new Node(5, "关胜");

        //说明，我们先手动创建该二叉树，后面我们学习递归的方式创建二叉树
        //这里为了测试快速查找，需要按照顺序排列
        root.leftNode = node2;
        root.rightNode = node3;
        node3.rightNode = node4;
        node3.leftNode = node5;
        binaryTree.setRoot(root);


        System.out.println("前序遍历方式~~~");
        Node preNode = binaryTree.preFind(5);
        if (preNode != null) {
            System.out.printf("找到了，信息为 no=%d name=%s", preNode.no, preNode.name);
        } else {
            System.out.printf("没有找到 no = %d 的英雄", 5);
        }

        System.out.println("中序遍历方式~~~");
        Node midNode = binaryTree.midFind(5);
        if (preNode != null) {
            System.out.printf("找到了，信息为 no=%d name=%s", midNode.no, midNode.name);
        } else {
            System.out.printf("没有找到 no = %d 的英雄", 5);
        }


        System.out.println("后序遍历方式~~~");
        Node postNode = binaryTree.postFind(5);
        if (preNode != null) {
            System.out.printf("找到了，信息为 no=%d name=%s", postNode.no, postNode.name);
        } else {
            System.out.printf("没有找到 no = %d 的英雄", 5);
        }




    }
}


